package org.hackystat.ui.chart.jfc.chartresource.dataset;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.awt.Color;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the TelemetryXYSeries class normal operations.
 * 
 * @author Pavel Senin.
 * 
 */
public class TestTelemetryXYSeries {

  /** object under testing. */
  private TelemetryXYSeries testSeries;

  /**
   * Creates empty TelemetryXYSeries.
   * 
   * @throws Exception when test doesn't want to work.
   */
  @Before
  public void setUp() throws Exception {
    testSeries = new TelemetryXYSeries();
  }

  /**
   * Does nothing so far.
   * 
   * @throws Exception when test doesn't want to work.
   */
  @After
  public void tearDown() throws Exception {
    assert true;
  }

  /**
   * Tests the constructor.
   * 
   */
  @Test
  public void testTelemetryXYSeries() {
    assertNull("Asserting null color", testSeries.getColor());
    assertEquals("Testing empty storage", 0, testSeries.getSeriesData().size());
  }

  /**
   * Tests color operations.
   * 
   */
  @Test
  public void testSetColor() {
    testSeries.setColor(Color.RED);
    assertEquals("Testing empty storage", Color.RED, testSeries.getColor());
  }

  /**
   * Tests TelemetryXYSeries data operations.
   * 
   * @throws TelemetryXYSeriesException if data got overridden.
   */
  @Test
  public void testAdd() throws TelemetryXYSeriesException {
    testSeries.add(0.1D, 0.15D);
    testSeries.add(0.2D, 0.2D);
    testSeries.add(0.3D, 0.25D);
    assertEquals("Testing series, case #1", 0.15D, testSeries.getSeriesData().get(0.1D));
    assertEquals("Testing series, case #2", 0.2D, testSeries.getSeriesData().get(0.2D));
    assertEquals("Testing series, case #3", 0.25D, testSeries.getSeriesData().get(0.3D));

    try {
      testSeries.add(0.3D, 0.23D);
      fail("Didn't get exception while overriding the data");
    }
    catch (TelemetryXYSeriesException e) {
      assert true;
    }
  }

}
